package com.zhuiyun.project.api.system.dict.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.system.dict.entity.DictData;
import com.zhuiyun.project.api.system.dict.service.DictDataService;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName DictDataController
 * @Description TODO 字典详情控制层
 * @Author gpd
 * @Date 2023-06-16 上午 10:06
 **/
@RestController
@Api(tags = "字典详情管理")
@Slf4j
@CrossOrigin
@RequestMapping("/dictData")
public class DictDataController extends BaseController {

    @Autowired
    DictDataService dictDataService;

    @GetMapping("/test/{dictType}")
    public CommonResult test(@PathVariable String dictType){
        return CommonResult.ok(dictType + "hhhhhhh");
    }

    /**
    * @Author gpd
    * @Description 根据字典类型查询字典数据信息
    * @Date 2023-06-16 上午 10:11
    * @Return CommonResult

    */
    @GetMapping(value = "/type/{dictType}")
    @ApiOperation(value = "根据字典类型查询字典数据信息")
    @OptLog(modular = "字典详情管理", type = CommonConstants.SELECT, describe = "根据字典类型查询字典数据信息")
    public CommonResult type(@PathVariable String dictType){
        return CommonResult.ok(dictDataService.type(dictType));
    }

    /**
    * @Author gpd
    * @Description 字典详情分页查询
    * @Date 2023-06-19 下午 02:27
    * @Return PageResult

    */
    @PreAuthorize("@ss.hasPermi('system:dict:list')")
    @ApiOperation(value = "字典详情分页查询")
    @OptLog(modular = "字典详情管理", type = CommonConstants.SELECT, describe = "字典详情分页查询")
    @GetMapping("/list")
    public CommonResult list(PageRequest request, DictData dictData){
        IPage<DictData> list = dictDataService.list(request, dictData);
        return CommonResult.ok(list);
    }

    /**
     * @Author gpd
     * @Description 查询字典数据详细(用于修改按钮的回显)
     * @Date 2023-06-19 下午 03:03
     * @Return CommonResult

     */
    @PreAuthorize("@ss.hasPermi('system:dict:query')")
    @ApiOperation(value = "查询字典数据详细(用于修改按钮的回显)")
    @OptLog(modular = "字典详情管理", type = CommonConstants.SELECT, describe = "查询字典数据详细(用于修改按钮的回显)")
    @GetMapping(value = "/{dictCode}")
    public CommonResult getData(@PathVariable Long dictCode){
        return CommonResult.ok(dictDataService.dictCode(dictCode));
    }

    /**
    * @Author gpd
    * @Description 新增字典详情
    * @Date 2023-06-19 下午 03:17
    * @Return CommonResult

    */
    @PreAuthorize("@ss.hasPermi('system:dict:add')")
    @ApiOperation(value = "新增字典详情")
    @OptLog(modular = "字典详情管理", type = CommonConstants.ADD, describe = "新增字典详情")
    @PostMapping("/addDictData")
    public CommonResult addDictData(@RequestBody DictData dictData){
        return CommonResult.ok(dictDataService.addDictData(dictData));
    }

    /**
    * @Author gpd
    * @Description 修改字典详情
    * @Date 2023-06-19 下午 03:23
    * @Return CommonResult

    */
    @PreAuthorize("@ss.hasPermi('system:dict:edit')")
    @ApiOperation(value = "修改字典详情")
    @OptLog(modular = "字典详情管理", type = CommonConstants.UPDATE, describe = "修改字典详情")
    @PutMapping("/updateDictData")
    public CommonResult updateDictData(@RequestBody DictData dictData){
        return CommonResult.ok(dictDataService.updateDictData(dictData));
    }

    /**
    * @Author gpd
    * @Description 删除字典详情
    * @Date 2023-06-19 下午 03:31
    * @Return CommonResult

    */
    @PreAuthorize("@ss.hasPermi('system:dict:remove')")
    @ApiOperation(value = "删除字典详情")
    @OptLog(modular = "字典详情管理", type = CommonConstants.DELETE, describe = "删除字典详情")
    @DeleteMapping("/{dictCode}")
    public CommonResult deleteDictData(@PathVariable Long[] dictCode){
        return CommonResult.ok(dictDataService.deleteDictData(dictCode));
    }
}
